package com.omuao.message.queue.core.config;

import com.omuao.message.queue.core.queue.MessageOutListener;
import com.omuao.message.queue.core.rocketmq.MessageChannelProcessor;
import com.omuao.message.queue.utils.RocksDbUtils;
import org.rocksdb.RocksDB;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * 数据库配置
 *
 * @author omuao
 */
@Configuration
public class DbConfigs {

    public static Logger logger = LoggerFactory.getLogger(DbConfigs.class);

    @Autowired
    MessageChannelProcessor messageChannelProcessor;

    @Bean("delayDb")
    public RocksDB delayDb() throws IOException {
        return RocksDbUtils.build("delay");
    }

    @Bean("delayTemplateDb")
    public RocksDB delayTemplateDb() throws IOException {
        return RocksDbUtils.build("delay-template");
    }

    @Bean("delayMessageOutListener")
    public MessageOutListener delayMessageOutListener() {
        return new MessageOutListener() {
            @Override
            public boolean output(String message) {
                logger.info("已发出消息：{}。", message);
                //TODO 发送到RocketMQ
                return true;
            }
        };
    }


}
